﻿using PowerBooking.RSE.Poco;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Objects;
using System.Linq;
using System.Text;
using PowerBooking.RSE.IRepository;
using PowerBooking.RSE.Repository.Contexts;

namespace PowerBooking.RSE.Repository.Repositories
{
    /// <summary>
    /// 蜘蛛仓储
    /// </summary>
    public class SpiderRepository : RestaurantSpiderEngineRepository, ISpiderRepository
    {
        public SpiderRepository(IUnitOfWork unitOfWork) : base(unitOfWork) { }

        /// <summary>
        /// 获取一只蜘蛛
        /// </summary>
        /// <param name="spiderID"></param>
        /// <returns></returns>
        public SpiderPoco QuerySpiderBySpiderID(int spiderID)
        {
            return Context.Spiders.SingleOrDefault(s => s.SpiderID == spiderID);
        }

        /// <summary>
        /// 获取所有蜘蛛
        /// </summary>
        /// <returns></returns>
        public IEnumerable<SpiderPoco> GetAllSpiders()
        {
            return Context.Spiders;
        }

        /// <summary>
        /// 插入一个蜘蛛
        /// </summary>
        /// <param name="spiderPoco"></param>
        /// <returns></returns>
        public void InsertSpider(SpiderPoco spiderPoco)
        {
            Context.Spiders.AddObject(spiderPoco);
            Context.SaveChanges(SaveOptions.None);
        }
    }
}
